public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 4; i++) {
                System.out.println("t2");
                try{
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        });

        Thread t1 =new Thread(()->{
            try {
                //Thread.sleep(500);
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < 3; i++) {
                System.out.println("t1");
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        Thread.sleep(500);//这里主线程会休眠500毫秒,t1进入try,并且t2没有启动,所以无法join,则t1无法阻塞(join调用时会立即返回,继续执行t1代码)
        t2.start();

        //main 只等 t1
        t1.join();
        System.out.println("main end");
    }
}
